package br.com.erpcortume.DAO;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import br.com.erpcortume.beans.Fornecedor;
import br.com.erpcortume.repositorio.FornecedorRepositorio;

@Component
@Transactional
public class FornecedorDAO implements FornecedorRepositorio{

	private SessionFactory sf;
	
	@Autowired
	public FornecedorDAO(SessionFactory factory){
		this.sf = factory;
	}
	
	private Session getSession(){
		return sf.getCurrentSession();
	}
	
	
	public void salvar(Fornecedor fornecedor) {
		getSession().save(fornecedor);
	}


	@SuppressWarnings("unchecked")
	public List<Fornecedor> listar() {
		return getSession().createCriteria(Fornecedor.class).list();
	}


	public void editar(Fornecedor fornecedor) {
		getSession().update(fornecedor);
	}

	public Fornecedor findById(int id) {
		return (Fornecedor) getSession().get(Fornecedor.class, id);
	}

	public void delete(Fornecedor fornecedor) {
		getSession().delete(fornecedor);
	}

	
	
}
